package com.yxkj.syh.app.huarong.data_center.model;

import com.syh.app.basic.utils.net.ApiObserver;
import com.yxkj.syh.app.huarong.bean.ReceiveRequest;
import com.yxkj.syh.app.huarong.util.RetrofitHelper;
import com.trello.rxlifecycle2.LifecycleTransformer;
import com.yxkj.syh.app.huarong.api.OrderApi;
import com.yxkj.syh.app.huarong.bean.PagesRequest;

import java.util.Map;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * 创建者：SYH
 * 时间：2020/5/22 13:57
 * 编辑者：SYH、
 * 标签：
 * 补充说明：
 */
public class OrderModel {
    private static OrderModel orderModel;

    private OrderModel() {
    }

    public static OrderModel getOrderModel() {
        if (orderModel == null) orderModel = new OrderModel();
        return orderModel;
    }

    private OrderApi getOrderApi() {
        return RetrofitHelper.createApi(OrderApi.class);
    }

    public void orderList(PagesRequest request, LifecycleTransformer transformer, ApiObserver apiObserver) {
        getOrderApi().orderList(request).compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }
    public void saleManList( LifecycleTransformer transformer, ApiObserver apiObserver) {
        getOrderApi().saleManList().compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

    public void goodsList( LifecycleTransformer transformer, ApiObserver apiObserver) {
        getOrderApi().goodsList().compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

    public void paperFactoryList( LifecycleTransformer transformer, ApiObserver apiObserver) {
        getOrderApi().paperFactoryList().compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

    public void creatOrder( Map<String,Object> orderInfo, LifecycleTransformer transformer, ApiObserver apiObserver) {
        getOrderApi().creatOrder(orderInfo).compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }
    public void orderDetail(long id, LifecycleTransformer transformer, ApiObserver apiObserver) {
        getOrderApi().orderDetail(id).compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

    public void editAddress(Map<String,Object> info, LifecycleTransformer transformer, ApiObserver apiObserver) {
        getOrderApi().editOrderAddress(info).compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

    public void cancelOrder(Map<String,Object> pMap, LifecycleTransformer transformer, ApiObserver apiObserver) {
        getOrderApi().cancelOrder(pMap).compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

    public void scanCarId(Map<String,Object> pMap, LifecycleTransformer transformer, ApiObserver apiObserver) {
        getOrderApi().scanCarId(pMap).compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

    public void faHuo(Map<String,Object> pMap, LifecycleTransformer transformer, ApiObserver apiObserver) {
        getOrderApi().faHuo(pMap).compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

    public void editGoodsOrPayment(Map<String,Object> pMap, LifecycleTransformer transformer, ApiObserver apiObserver) {
        getOrderApi().editGoodsOrPayment(pMap).compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

    public void receive(ReceiveRequest request, LifecycleTransformer transformer, ApiObserver apiObserver) {
        getOrderApi().receive(request).compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }


    public void returnGoods(Map<String,Object> pMap, LifecycleTransformer transformer, ApiObserver apiObserver) {
        getOrderApi().returnGoods(pMap).compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }



}
